package day23;

import java.util.*;

public class Gift {
    public int getValue(int[] gifts, int n) {
        // write code here
        int nums = n / 2;
        Arrays.sort(gifts);
        if(gifts[nums] >= nums) {
            int count = 0;
            for(int i = 0; i < n; i++) {
                if(gifts[i] == gifts[nums]) {
                    count++;
                }
            }
            if(count >= nums) {
                return gifts[nums];
            }
        }
        return 0;
    }
}